package com.yayhos.parallaxrecyclerview;

import ohos.agp.components.Component;

public abstract class ParallaxViewHolder implements ParallaxImageView.ParallaxImageListener {
    private ParallaxImageView backgroundImage;
    Component component;

    public ParallaxViewHolder(Component component) {
        this.component = component;
        backgroundImage = (ParallaxImageView) component.findComponentById(getParallaxImageId());
        backgroundImage.setListener(this);
    }

    public abstract int getParallaxImageId();

    @Override
    public int[] requireValuesForTranslate() {
        int[] itemPosition;
        itemPosition = component.getLocationOnScreen();
        int[] recyclerPosition = new int[2];
        return new int[]{itemPosition[1], 2499, recyclerPosition[1]};

    }

    public void animateImage() {
        getBackgroundImage().doTranslate();
    }

    public ParallaxImageView getBackgroundImage() {
        return backgroundImage;
    }
}
